package Communication;

import java.util.ArrayList;

import Communication.NoeudPheromone;
/**
 * TODO description
 */
public class AretePheromone {

	private ArrayList<Pheromone> pheromones;
	private NoeudPheromone arrive;
	private NoeudPheromone depart;
	
	public AretePheromone(NoeudPheromone dep , NoeudPheromone arr)
	{
		depart  = dep;
		arrive  = arr;
		pheromones = new ArrayList<Pheromone>();
	}
	
	public ArrayList<Pheromone> getPheromones()
	{
		return pheromones;
	}
	
	public int getPheromoneValue(String name)
	{
		for(Pheromone p : pheromones)
			if(p.getName().equals(name))
				return p.getValue();
	
		return 0;
	}
	
	public Pheromone getPheromone(String name)
	{
		for(Pheromone p : pheromones)
			if(p.getName().equals(name))
				return p;
		
		return null;
	}
	
 	public void removePheromone(Pheromone p)
	{
		if(pheromones.contains(p))
			pheromones.remove(p);
	}
 	
 	public void addPheromone(Pheromone ph)
 	{
 		Pheromone oldP = null;
 		
 		for(Pheromone p : pheromones)
			if(p.getName().equals(ph.getName()))
				oldP = p;
 		
 		if(oldP != null)
 		{
 			oldP.setValue(ph.getValue());
 		}
 		else
 		{
 			pheromones.add(ph);
 			GraphPheromone.getSingleton().addPheromoneGraph(this,ph);
 		}
 	}
 	
 	public NoeudPheromone getArrive()
 	{
 		return arrive;
 	}
 	
 	public NoeudPheromone getDepart()
 	{
 		return depart;
 	}
}